// javascript document var flag=false; function drawimage(imgd,imgwidth,imgheight) { var image=new image(); var iwidth = imgwidth; //定义允许图片宽度 var iheight =imgheight; //定义允许图片高度 image.src=imgd.src; if(image.width>0 && image.height>0) { flag=true; if(image.width/image.height>= iwidth/iheight) { if(image.width>iwidth) { imgd.width=iwidth; imgd.height=(image.height*iwidth)/image.width; } else { imgd.width=image.width; imgd.height=image.height; } } else { if(image.height>iheight) { imgd.height=iheight; imgd.width=(image.width*iheight)/image.height; } else { imgd.width=image.width; imgd.height=image.height; } } } }